#include "server.h"
#include <iostream>
#include <csignal>

volatile sig_atomic_t running = 1;

void signal_handler(int sig) {
    running = 0;
}

int main(int argc, char* argv[]) {
    // 设置信号处理
    std::signal(SIGINT, signal_handler);
    std::signal(SIGTERM, signal_handler);

    int port = 8080;
    if (argc > 1) {
        port = std::atoi(argv[1]);
    }

    try {
        Server server;
        std::cout << "Starting Student Course System Server on port " << port << std::endl;
        std::cout << "Press Ctrl+C to stop the server" << std::endl;

        server.run(port);

    } catch (const std::exception& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }

    return 0;
}
